<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ncp.model.entity.comment.Replybean"%>
<%@page import="com.ncp.model.entity.comment.Articlebean"%>
<%@page import="com.ncp.model.biz.bbs.ReplyProcess"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%

int showPages=5;
int size=2;
ArrayList<Replybean> rlist=(ArrayList<Replybean>)request.getAttribute("rlist");
Articlebean ab=(Articlebean)request.getAttribute("ab");
if(rlist==null||ab==null){
	response.sendRedirect("showarticle.jsp");
	return;
}
int nowPage=Integer.parseInt((String)request.getAttribute("nowPage"));
int PageCount=Integer.parseInt((String)request.getAttribute("pageCount"));
ReplyProcess rp=new ReplyProcess();
int n=0;
Replybean rb1=null;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showreplay.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
  <link rel="stylesheet" href="css/common.css" type="text/css"/>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
	function reply(id){
		alert(id);
		
		document.getElementById("reply").innerHTML=document.getElementById("r").innerText
		
	}
	</script>
  </head>
  
  <body>
  
  <div id="allpage">
	<div id="nav">
		<ul id="nav_item">
			<li><a href="#">网站首页</a></li>
			<li><a href="#">关于我们</a></li>

			<li><a href="#">新闻动态</a></li>
			<li><a href="#">产品展示</a></li>
			<li><a href="#">产品订购</a></li>
			<li><a href="#">资料下载</a></li>
			<li><a href="#">联系方式</a></li>
		</ul>

	</div>
	<div style="width:800px; padding:0 40px; font-size:14px; margin:0 auto;">
				   <div border="1">
				   <style>
				   table , tr , td{ width:800px;}
				   .title{}
				   .resource{ margin:30px 0;}
				   .assess{ margin-top:20px;}
				   .name{color:#ff4800;}
				   .con{color:#969696; font-size:11px;}
				 
				   .content{border-bottom:1px solid #ccc; line-height:24px;}
				   </style>
					  <div class="title">
					    <div height="34">标题:<%=ab.getTitle() %></td>
					  </div>
					  <div>
					    <div height="87" class="content"> 
					    	
						    <p class="assess">
						 	 <span class="right"><%=++n %>楼</span>  内容:aaaaaaaaaa
						 	 
						 	 <%=ab.getConn() %>
						 	 <div style="clear:both"></div>
						 	</p>
					    	<p class="resource">
					    	<span class="right"><%=ab.getPdate() %><a style="margin-left:20px;" href="">回复</a></span>用户:<span class="name"><%=ab.getUsername() %></span>
					    	</p>
					    </div>
					  </div>
				  <%
				  for(Replybean rb:rlist){
					  %>
					    <div>
				    <div height="87" class="content"> 
				    <%if(rb.getPid()!=0){ 
				    	rb1=rp.replyDetail(rb.getPid());
				    %>
				    <div border="1" id="r">
				      <div>
				      
				        <div>
						    <p class="assess con">引用<%=rb1.getUsername() %>:<%=rb1.getReplay() %></p></td>
				      </div>
				    </div>
				    <%	
				    }
				    %>
				    <p class="assess" style="padding:0 50px;">
				    <span style="font-size:12px; color:#000;" class="right"><%=++n %>楼</span>
				   	<%=rb.getReplay() %>
				   	</p>
				   <p class="resource">
				   <span class="right"><%=rb.getPdate() %><a style="margin-left:20px;" href="reply.jsp?rootid=<%=ab.getId() %>&id=<%=rb.getId() %>">回复</a>/<a style="margin-left:20px;" onclick="return confirm('确定要删除?')" href="AdminServlet?type=reply&rootid=<%=ab.getId() %>&id=<%=rb.getId() %>">删除</a></span>用户:<span class="name"><%=rb.getUsername() %></span>
				   <div style="clear:both"></div>
				   </p>
				 
				   </div>
				  </div>
					  <%
				  }
				  %>
				  <div id="page">
					<ul>
					
					<% 
					if(nowPage>1){
						%><li><a href="ShowReplyServlet?nowPage=<%= nowPage-1 %>&id=<%=ab.getId() %>" class="page">上一页</a></li><%
					}
					
					
					
						if(PageCount>=showPages){
							if(nowPage-size<=0){
								for(int i=1;i<=showPages;i++){
									%>
									
									<li><a href="ShowReplyServlet?nowPage=<%=i %>&id=<%=ab.getId() %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size<PageCount){
								for(int i=nowPage-size;i<=nowPage+size;i++){
									%>
									
									<li><a href="ShowReplyServlet?nowPage=<%=i %>&id=<%=ab.getId() %>" class="num" ><%=i %></a></li>
									<%
								}
								%><li>...</li><%
							}else if(nowPage+size>=PageCount){
								for(int i=PageCount-showPages+1;i<=PageCount;i++){
									%>
									
									<li><a href="ShowReplyServlet?nowPage=<%=i %>&id=<%=ab.getId() %>" class="num" ><%=i %></a></li>
									<%
								}
							}
						}else if(PageCount<=showPages){
							for(int i=1;i<=PageCount;i++){
								%>
								<li><a href="ShowReplyServlet?nowPage=<%=i %>&id=<%=ab.getId() %>" class="num" ><%=i %></a></li>
								<%
							}
						}
						
						if(nowPage<PageCount){
							%>
							<li><a href="ShowReplyServlet?nowPage=<%=nowPage+1 %>&id=<%=ab.getId() %>" class="page" ">下一页</a></li>
							<%
						}
						%>
						<li>共<%=PageCount %>页&emsp;</li>
							
							<form action="ShowReplyServlet" method="get">
							<input name="id" type="hidden" value=<%= ab.getId()%>>
							<li><input type="submit" value="跳到"/></li>
							<li><input id="skip" type="text" name="nowPage" style="width:30px; border:1px solid #CCC;" value="<%=nowPage %>"/></li>
							<li>页</li>
							</form>
					</ul>
		</div>
				  <div>
				    <div height="34">
				    <form id="form1" name="form1" method="post" action="ReplyServlet">
				    <input type="hidden" name="id" value="<%=ab.getId() %>">
				    <input type="hidden" name="type" value="direct" >
				      <textarea style="border:1px solid #ccc; resize:none; margin:20px;" name="reply" cols="45" rows="5">
				      </textarea>
				      <input type="submit" style="border:2px solid #ccc; cursor:pointer;" value="提交" />
				    </form>
				    </div>
				  </div>
				
				</table>
			</div>
		</div>
  </body>
</html>
